﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace VERKProjectHopur16.Helpers
{
    public class Logger
    {
        /// <summary>
        /// This class uses the singleton method to create an instances for loggin.
        /// Creates a collection of LogMedia classes which are then called to log
        /// when an exception is throwned.
        /// </summary>
        private List<LogMedia> m_loggers = null;

        private static Logger theInstance = null;
        public static Logger Instance
        {
            get
            {
                if (theInstance == null)
                {
                    theInstance = new Logger();
                }
                return theInstance;
            }
        }
        private Logger()
        {
            m_loggers = new List<LogMedia>();
            m_loggers.Add(new TextFileLogMedia { });
            m_loggers.Add(new EmailLogMedia { });
        }
        public void LogException(Exception ex)
        {
            foreach (LogMedia log in m_loggers)
            {
                log.LogMessage(string.Format("{0} exception was thrown on the {1}.{4}For: {2}{3}{4}",
                ex.Message, DateTime.Now, ex.Source, ex.StackTrace, Environment.NewLine));
            }
        }
    }
}